package com.example.makerspace.dao;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.example.makerspace.domain.ContactInfoDO;
import com.example.makerspace.dto.ContactInfoDTO;
import com.example.makerspace.mapper.ContactInfoMapper;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.Resource;

@Component
public class ContactInfoDAO extends BaseDAO<ContactInfoDO>{

    public final static String REF_TYPE = "ref_type";
    public final static String USERNAME = "username";
    public final static String REF_ID = "ref_id";
    public final static String NAME = "name";
    public final static String CONTACT = "contact";
    public final static String PHONE = "phone";
    public final static String EMAIL = "email";

    @Resource
    private ContactInfoMapper contactInfoMapper;

    @PostConstruct
    public void init(){
        this.mapper = contactInfoMapper;
    }

    public ContactInfoDO selectDupInfo(ContactInfoDTO contactInfoDTO){
        return contactInfoMapper.selectOne(new QueryWrapper<ContactInfoDO>()
                .eq(USERNAME, contactInfoDTO.getUsername())
                .eq(REF_ID, contactInfoDTO.getRefId())
                .eq(REF_TYPE, contactInfoDTO.getRefType())
                .eq(NAME, contactInfoDTO.getName())
                .eq(CONTACT, contactInfoDTO.getContact())
                .eq(PHONE, contactInfoDTO.getPhone())
                .eq(EMAIL, contactInfoDTO.getEmail()));
    }

    public ContactInfoDO selectByRef(ContactInfoDTO contactInfoDTO){
        return contactInfoMapper.selectOne(new QueryWrapper<ContactInfoDO>()
                .eq(USERNAME, contactInfoDTO.getUsername())
                .eq(REF_TYPE, contactInfoDTO.getRefType())
                .eq(REF_ID, contactInfoDTO.getRefId()));
    }

}
